﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using SFP;
using SFP.Input;

namespace HamsterDelivery.Menus
{
    public abstract class Menu
    {
        public Option DefaultOption { get; set; }
        public Option ActiveOption { get; set; }

        public abstract void update(KeyboardState keyStates);
        public abstract void draw(Graphics g);

        public abstract class Option
        {
            public Menu Menu { get; set; }
            
            public int X { set; get; }
            public int Y { set; get; }

            public Option UpOption { set; get; }
            public Option DownOption { set; get; }
            public Option LeftOption { set; get; }
            public Option RightOption { set; get; }

            public Option(Menu menu, int x, int y)
            {
                Menu = menu;
                X = x;
                Y = y;
            }

            public void update(KeyboardState keyStates)
            {
                if (keyStates.isKeyDownNotPressed(Keys.Up) || keyStates.isKeyDownNotPressed(Keys.W))
                {
                    if (UpOption != null) Menu.ActiveOption = UpOption;
                }
                else if (keyStates.isKeyDownNotPressed(Keys.Down) || keyStates.isKeyDownNotPressed(Keys.S))
                {
                    if (DownOption != null) Menu.ActiveOption = DownOption;
                }
                else if (keyStates.isKeyDownNotPressed(Keys.Left) || keyStates.isKeyDownNotPressed(Keys.A))
                {
                    if (LeftOption != null) Menu.ActiveOption = LeftOption;
                }
                else if (keyStates.isKeyDownNotPressed(Keys.Right) || keyStates.isKeyDownNotPressed(Keys.D))
                {
                    if (RightOption != null) Menu.ActiveOption = RightOption;
                }
                else if (keyStates.isKeyDownNotPressed(Keys.Enter) || keyStates.isKeyDownNotPressed(Keys.Space))
                {
                    doAction();
                }
            }

            public abstract void draw(Graphics g);
            public abstract void doAction();
        }
    }
}
